package org.robert.export_client.excel.metadata;

import lombok.*;

import java.io.Serializable;
import java.util.Arrays;
import java.util.List;

/**
 * ExcelHeadEntity:
 *
 * @author zhaoshengtao
 * @date 2024/01/19
 */
@Builder
@EqualsAndHashCode
@NoArgsConstructor
@AllArgsConstructor
@Data
public class ExcelHeadEntity implements Serializable {

    private static final long serialVersionUID = 6238625944931482398L;
    /**
     * 一级字段名， 如果是拼接，这个是第一个字段
     */
    private String fieldName;

    /**
     * 二级字段名
     */
    private String subFieldName;

    /**
     * excel中的标题名
     */
    private String columnName;

    /**
     * 排序
     */
    private int columnIndex;

    /**
     * 字段宽度
     */
    private int columnWidth;

    /**
     * 字典对象
     */
    private ExcelDictEntity dictEntity;

    /**
     * 是否时json. 默认flase
     */
    private boolean isJson;

    /**
     * json解析的实体 如果有
     */
    private Class<?> jsonClazz;

    /**
     * 时间解析格式
     */
    private String dateFormat;

    /**
     * 是否需要拼接
     */
    private boolean isConnect = false;

    /**
     * 拼接的字段集合，
     */
    private String[] fieldNames;

    /**
     * 拼接的字符，默认是英文逗号
     */
    private String connectType;

    /**
     * 是否依赖其他字段或值
     */
    private boolean isDepend = false;

   private DependEntity dependEntity;


    public String getFiled() {
        if(this.isJson){
            return subFieldName;
        }
        return fieldName;
    }

    @Override
    public String toString() {
        return "ExcelHeadEntity{" +
                "fieldName='" + fieldName + '\'' +
                ", subFieldName='" + subFieldName + '\'' +
                ", columnName='" + columnName + '\'' +
                ", columnIndex=" + columnIndex +
                ", columnWidth=" + columnWidth +
                ", dictEntity=" + dictEntity +
                ", isJson=" + isJson +
                ", jsonClazz=" + jsonClazz +
                ", dateFormat='" + dateFormat + '\'' +
                ", isConnect=" + isConnect +
                ", fieldNames=" + Arrays.toString(fieldNames) +
                ", connectType='" + connectType + '\'' +
                '}';
    }
}
